package com.yz.xyt.controller;

import com.yz.xyt.constant.HttpStatus;
import com.yz.xyt.domain.ResponseResult;
import com.yz.xyt.domain.Staff;
import com.yz.xyt.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 教职工同步接口
 * @author JW.WANG
 */
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    IStaffService staffService;

    /**
     * 同步增量
     * @param list
     * @return
     */
    @PostMapping("/syncAdd")
    public ResponseResult syncAddStaff(@RequestBody List<Staff> list){

        ResponseResult result = new ResponseResult();

        //获取传递的参数
        if(Objects.isNull(list)){
            result.setCode(HttpStatus.NOT_IMPLEMENTED);
            result.setMsg("参数错误");
        }else{
            staffService.syncAddStaff(list);
            result.setCode(HttpStatus.SUCCESS);
            result.setMsg("教职工信息增量同步成功");
        }

        return result;
    }
    /**
     * 同步更新
     * @param list
     * @return
     */
    @PostMapping("/syncUpdate")
    public ResponseResult syncUpdateStaff(@RequestBody List<Staff> list){

        ResponseResult result = new ResponseResult();

        //获取传递的参数
        if(Objects.isNull(list)){
            result.setCode(HttpStatus.NOT_IMPLEMENTED);
            result.setMsg("参数错误");
        }else{
            staffService.syncUpdateStaff(list);
            result.setCode(HttpStatus.SUCCESS);
            result.setMsg("教职工信息更新同步成功");
        }

        return result;
    }
    /**
     * 同步删除
     * @param list
     * @return
     */
    @PostMapping("/syncDelete")
    public ResponseResult syncDeleteStaff(@RequestBody List<Staff> list){

        ResponseResult result = new ResponseResult();

        //获取传递的参数
        if(Objects.isNull(list)){
            result.setCode(HttpStatus.NOT_IMPLEMENTED);
            result.setMsg("参数错误");
        }else{
            staffService.syncDeleteStaff(list);
            result.setCode(HttpStatus.SUCCESS);
            result.setMsg("教职工信息删除同步成功");
        }

        return result;
    }
}
